package kr.pe.johnkim.waiting.mobile.dao;

import kr.pe.johnkim.waiting.mobile.domain.WaitingRecommendation;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 6. 17.
 */
@Repository
public class WaitingRecommendationDaoImpl extends SqlSessionDaoSupport implements WaitingRecommendationDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(WaitingRecommendationDaoImpl.class);

    /**
     * 사용자의 추천 중복을 확인 한다.
     *
     * @param waitingRecommendation
     * @return
     */
    @Override
    public WaitingRecommendation selectDuplicationRecommendation(WaitingRecommendation waitingRecommendation) {
        logger.info("selectDuplicationRecommendation");
        return (WaitingRecommendation)this.getSqlSession().selectOne("WAITING_RECOMMENDATION.selectDuplicationRecommendation", waitingRecommendation);
    }

    /**
     * 추천을 등록 한다.
     *
     * @param waitingRecommendation
     */
    @Override
    public void registerRecommendation(WaitingRecommendation waitingRecommendation) {
        logger.info("registerRecommendation");
        this.getSqlSession().insert("WAITING_RECOMMENDATION.registerRecommendation", waitingRecommendation);
    }

    /**
     * 추천 정보를 업데이트 한다.
     *
     * @param waitingRecommendation
     */
    @Override
    public void updateRecommendation(WaitingRecommendation waitingRecommendation) {
        logger.info("updateRecommendation");
        this.getSqlSession().update("WAITING_RECOMMENDATION.updateRecommendation", waitingRecommendation);
    }

    /**
     * 추천을 비활성화 한다.
     *
     * @param waitingRecommendation
     */
    @Override
    public void updateDeactivateRecommendation(WaitingRecommendation waitingRecommendation) {
        logger.info("updateDeactivateRecommendation");
        this.getSqlSession().update("WAITING_RECOMMENDATION.updateDeactivateRecommendation", waitingRecommendation);
    }

    /**
     * 검색한 가맹점들에 대한 추천 목록을 가져 온다.
     *
     * @param waitingRecommendation
     * @return
     */
    @Override
    public List<WaitingRecommendation> selectSearchRecommendationList(WaitingRecommendation waitingRecommendation) {
        logger.info("selectSearchRecommendationList");
        return this.getSqlSession().selectList("WAITING_RECOMMENDATION.selectSearchRecommendationList", waitingRecommendation);
    }

    /**
     * 특정 가맹점에 대한 추천 정보를 가져 온다.
     *
     * @param waitingRecommendation
     * @return
     */
    @Override
    public WaitingRecommendation selectRecommendationInformation(WaitingRecommendation waitingRecommendation) {
        logger.info("selectRecommendationInformation");
        return (WaitingRecommendation)this.getSqlSession().selectOne("WAITING_RECOMMENDATION.selectRecommendationInformation", waitingRecommendation);
    }

    /**
     * 사용자가 최초 등록한 추천을 가져 온다.
     * 추천을 최초 등록할때 호출한다.
     *
     * @param waitingRecommendation
     * @return
     */
    @Override
    public WaitingRecommendation selectRecentRecommendationInformation(WaitingRecommendation waitingRecommendation) {
        logger.info("selectRecentRecommendationInformation");

        logger.info("> merchantId : {}", waitingRecommendation.getMerchantId());
        logger.info("> creator    : {}", waitingRecommendation.getCreator());
        logger.info("> activateYn : {}", waitingRecommendation.getActivateYn());

        return (WaitingRecommendation)this.getSqlSession().selectOne("WAITING_RECOMMENDATION.selectRecentRecommendationInformation", waitingRecommendation);
    }


}
